import requests


def download_file(url, local_url, timeout=10, retry=2):
    for i in range(retry):
        try:
            r = requests.head(url, timeout=timeout)
            r.raise_for_status()
            Content_Length = int(r.headers["Content-Length"])
        except Exception as e:
            print(e)
            continue
        download_Length=0
        headers={}
        while download_Length < Content_Length:
            headers["Range"] = "bytes=%d-%d"%(download_Length, download_Length+65536)
            r = requests.get(url, timeout=timeout, headers = headers)
            with open(local_url, 'ab+') as f:
                f.write(r.content)
                download_Length += len(r.content)
        return True
    return False